package com.kgc.project.projectmanagerservice.service;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.project.bean.Projectinfo;
import com.kgc.project.bean.ProjectinfoExample;
import com.kgc.project.projectmanagerservice.mapper.ProjectinfoMapper;
import com.kgc.project.service.ProService;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProServiceImpl implements ProService {
    @Resource
    ProjectinfoMapper projectinfoMapper;
    @Override
    public String getProByStatus(Integer status,Integer pageNum) {
        PageHelper.startPage(pageNum,1);
        PageHelper.orderBy("id desc");
        List<Projectinfo> projectinfos=null;
        if(status!=0){
            ProjectinfoExample example=new ProjectinfoExample();
            example.createCriteria().andStatusEqualTo(status);
             projectinfos = projectinfoMapper.selectByExample(example);
        }else{
            projectinfos = projectinfoMapper.selectByExample(null);
        }
        PageInfo<Projectinfo> pageInfo=new PageInfo<>(projectinfos);
        String s= JSONObject.toJSONString(pageInfo, SerializerFeature.WriteMapNullValue,SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
        return s;
    }

    @Override
    public Projectinfo getById(Integer id) {
        return projectinfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer upPro(Projectinfo projectinfo) {
        return projectinfoMapper.updateByPrimaryKeySelective(projectinfo);
    }
}
